﻿/**********************************************************************
 * @file   FITKCGNSReader.h
 * @brief  CGNS 格式读取接口
 * @author liuzhonghua (liuzhonghuaszch@163.com)
 * @date   2024-09-19
 *********************************************************************/

#ifndef _FITKFCGNSREADER_H__
#define _FITKFCGNSREADER_H__

#include "FITKCGNSIOAPI.h"
#include "FITKCGNSData.h"
#include "FITK_Interface/FITKInterfaceIO/FITKAbstractIO.h"
#include <cgnslib.h>

namespace Interface {
    class FITKUnstructuredFluidMeshVTK;
    class FITKBoundaryMeshVTK;
}
namespace IO
{
    class FITKCGNSData;
    /**
     * @brief  CGNS读取
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2024-09-19
     */
    class FITKCGNSIOAPI FITKCGNSReader : public Interface::FITKAbstractIO
    {
    public:
        /**
         * @brief  构造函数
         * @author YanZhiHui (chanyuantiandao@126.com)
         * @date   2024-07-29
         */
        FITKCGNSReader() = default;
        /**
         * @brief  析构函数
         * @author YanZhiHui (chanyuantiandao@126.com)
         * @date   2024-07-29
         */
        ~FITKCGNSReader();
        /**
         * @brief 重写run函数
         * @author fulipeng (fulipengqd@yeah.net)
         * @date 2024-03-11
         */
        void run() override;

        /**
         * @brief 打印控制台消息
         * @param[i] level 打印级别 1 normal 2 warning 3error
         * @param[i] str 数据
         * @author fulipeng (fulipengqd@yeah.net)
         * @date 2024-04-07
         */
        void consoleMessage(int level, const QString& str) override;

    private:
        bool read();
        bool readFamily();
        bool readZone();
        bool readCoordinate(int vertext_num, /*int*/cgsize_t range_from[3], /*int*/cgsize_t range_to[3]);
        bool readZoneFlowSolution(int pointLen, int cellLen, cgsize_t* rmax_pt, cgsize_t* rmax_cell);

        bool readBoundaryCond(int index_bc);
        bool readZoneBCs(BCDataStruct* bcData, int index_bc, int cellCount);
        bool readUnstructZoneBCs(BCDataStruct* bcData, int index_bc);
        bool readStructZoneBCs(BCDataStruct* bcData, int index_bc);
        bool readSections();


        void readCells(SectionDataStruct* section, int start_index, int end_index, int type, cgsize_t* elements /*int* elements*/, int element_data_size);

        void setReadData();
        /**
         * @brief    根据风电求解器所需求的，仅会获取一个base进行计算
         * @return   int
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-09-24
         */
        int filterBaseIndex();
    private:
        /**
         * @brief  网格数据对象
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        Interface::FITKUnstructuredFluidMeshVTK* m_Mesh{};

        int m_index_file{ -1 };
        int m_index_base{ -1 };
        int m_index_zone{ -1 };
        int m_index_family{ -1 };

        FITKCGNSData* m_cgnsData{};
    };

}

#endif